package live.yanxiaohui.demo.confirm;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import live.yanxiaohui.demo.util.RabitMQConnection;

public class Producer {
    private static final String QUEUE_NAME = "game";

    public static void main(String[] args) throws Exception {
        // 1.创建连接
        Connection connection = RabitMQConnection.getConnection();
        // 2.设置通道
        Channel channel = connection.createChannel();
        // 开启消息确认机制
        channel.confirmSelect();
        // 3.设置消息
        String msg = "吃鸡上号???";
        System.out.println("msg:" + msg);
        channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
        System.out.println(channel.waitForConfirms());
        channel.close();
        connection.close();
    }
}
